#ifndef UTIL_H
#define UTIL_H

#include <stdio.h>

/* Utilities. The macro |die| shows a message with the line number,
file and function names, and aborts the execution of the program. If
|NDEBUG| macro is defined, no error is evaluated and no |debug|
information is printed. */


#ifdef NDEBUG
#define debug(format, ...) ;
#else
#define __print_location()						\
  fprintf(stdout, "%d:%s->%s(): ", __LINE__, __FILE__, __FUNCTION__)
#define __print_location_err()						\
  fprintf(stderr, "ERROR: %d:%s->%s(): ", __LINE__, __FILE__, __FUNCTION__)
#define debug(format, ...) __print_location();	\
  fprintf(stdout, format, ## __VA_ARGS__ )
#define die(format, ...)  do {\
    __print_location_err();					\
    fprintf(stderr, format, ## __VA_ARGS__);			\
    exit(-1);							\
  } while(0)
#endif

#endif
